; tpost0.g
; called after tool 0 has been selected

set global.DirectDriveExtruder = global.DirectDriveExtruderArray[0]
var gridCompensationOn =0
if move.compensation.file != null
    set var.gridCompensationOn =1
    G29 S2

;heatup
var firstExtrude =0
if heat.heaters[1].current < heat.coldExtrudeTemperature
    set var.firstExtrude =1
M116 P0 S30

;prime nozzle
if global.wipeNozzleEnable =1
    M98 P"prime.g"

M106 R2    ; Restore fan speed to the value it has when the print was paused (R1) or the last time the fan speed was set and no P parameter was provided (R2).

;G1 R2 X0 Y0 Z2 Fxxx
;G1 R2 X0 Y0 Z0 Fxxx

if move.axes[0].homed && move.axes[1].homed && move.axes[2].homed && global.offsetDetect =0    ;检测偏移时不恢复换头前的坐标, 其它时候需要恢复换头前的坐标
    if state.restorePoints[2].coords[1] > 175 && state.restorePoints[2].coords[0] > 150
        G1 R2 X0 F50000
        M400
        G1 R2 Y0 F50000
    else
        G1 R2 X0 Y0 F50000 ; When a print is paused the coordinates are saved to slot 1 automatically, and at the start of a tool change the coordinates are saved to slot 2 automatically.
    G1 R2 Z2 F50000
    if var.gridCompensationOn =1
        G29 S1
    G1 R2 Z0 F600

if heat.heaters[1].current > heat.coldExtrudeTemperature
    if var.firstExtrude =1
        G1 E{(global.DirectDriveExtruder =0 ? global.changeToolsRetracrion + global.retractLength : global.changeToolsRetracrionDDE + global.retractLengthDDE)} F{global.retractSpeedSlow*60}
    else
        G1 E{(global.DirectDriveExtruder =0 ? global.changeToolsRetracrion : global.changeToolsRetracrionDDE)} F{global.retractSpeedSlow*60}
